<template>
  <div class="container">
    <el-form ref="form" :model="form" label-width="80px" >
    <el-form-item label="学生学号" required="true">
        <el-input v-model="form.s_id"></el-input>
    </el-form-item>
    <el-form-item label="发送内容" required="true">
        <el-input type="textarea" v-model="form.msg"  maxlength="100"></el-input>
    </el-form-item>
    <el-form-item>
        <el-button type="primary" @click="onSubmit">发送</el-button>
    </el-form-item>
  </el-form>
  </div>
</template>

<script>
import { sendMsg } from '@/api/user'
export default {
  data() {
    return {
      form: {
        s_id: '',
        msg: '',
        teacher_id:''
      }
    }
  },
  methods: {
    onSubmit() {
      //检查学生学号是否为空
      if(this.form.s_id===''){
        this.$message({
          message: '学生学号不能为空',
          type: 'error'
        })
        return false
      }else if(this.form.msg===''){
        //检查内容是否为空
        this.$message({
          message: '请输入信件内容',
          type: 'error'
        })
        return false
      }else{
        this.form.teacher_id=this.$store.getters.t_id;
        sendMsg(this.form).then(response=>{
          this.$message({
            message: response.message,
            type: response.data.message
          })
        })
      }
      
      
    }
  }
}
</script>

<style>
  .container{
    margin-top: 30px;
    margin-inline: auto;
    width: 50%;
    
  }

</style>